package backend.Register;

import java.util.HashMap;

public class initReg {
    public static HashMap<Integer, physicalReg> phyRegs = new HashMap<>();
    public static HashMap<Integer, physicalFReg> phyfRegs = new HashMap<>();
    public static HashMap<Integer, physicalReg> phyA = new HashMap<>();
    public static HashMap<Integer, physicalFReg> fPhyA = new HashMap<>();
    public static physicalReg ZERO = new physicalReg("zero");
    public static physicalReg SP = new physicalReg("sp");
    public static physicalReg RA = new physicalReg("ra");
    public static int phycounter = 0;
    public static int fphycounter = 0;
    public static void init(){
        phyRegs.put(ZERO.getIndex(), ZERO);
        phyRegs.put(RA.getIndex(), RA);
        phyRegs.put(SP.getIndex(), SP);
        phyRegs.put(3, new physicalReg("gp"));
        phyRegs.put(4, new physicalReg("tp"));
        // t 寄存器
        phyRegs.put(5, new physicalReg("t0"));
        phyRegs.put(6, new physicalReg("t1"));
        phyRegs.put(7, new physicalReg("t2"));
        phyRegs.put(28, new physicalReg("t3"));
        phyRegs.put(29, new physicalReg("t4"));
        phyRegs.put(30, new physicalReg("t5"));
        phyRegs.put(31, new physicalReg("t6"));

        //s 寄存器
        phyRegs.put(8, new physicalReg("s0"));
        phyRegs.put(9, new physicalReg("s1"));
        phyRegs.put(18, new physicalReg("s2"));
        phyRegs.put(19, new physicalReg("s3"));
        phyRegs.put(20, new physicalReg("s4"));
        phyRegs.put(21, new physicalReg("s5"));
        phyRegs.put(22, new physicalReg("s6"));
        phyRegs.put(23, new physicalReg("s7"));
        phyRegs.put(24, new physicalReg("s8"));
        phyRegs.put(25, new physicalReg("s9"));
        phyRegs.put(26, new physicalReg("s10"));
        phyRegs.put(27, new physicalReg("s11"));

        // a 寄存器
        phyRegs.put(10, new physicalReg("a0"));
        phyA.put(0, phyRegs.get(10));
        phyRegs.put(11, new physicalReg("a1"));
        phyA.put(1, phyRegs.get(11));
        phyRegs.put(12, new physicalReg("a2"));
        phyA.put(2, phyRegs.get(12));
        phyRegs.put(13, new physicalReg("a3"));
        phyA.put(3, phyRegs.get(13));
        phyRegs.put(14, new physicalReg("a4"));
        phyA.put(4, phyRegs.get(14));
        phyRegs.put(15, new physicalReg("a5"));
        phyA.put(5, phyRegs.get(15));
        phyRegs.put(16, new physicalReg("a6"));
        phyA.put(6, phyRegs.get(16));
        phyRegs.put(17, new physicalReg("a7"));
        phyA.put(7, phyRegs.get(17));

        //浮点数 t 寄存器
        phyfRegs.put(0, new physicalFReg("ft0"));
        phyfRegs.put(1, new physicalFReg("ft1"));
        phyfRegs.put(2, new physicalFReg("ft2"));
        phyfRegs.put(3, new physicalFReg("ft3"));
        phyfRegs.put(4, new physicalFReg("ft4"));
        phyfRegs.put(5, new physicalFReg("ft5"));
        phyfRegs.put(6, new physicalFReg("ft6"));
        phyfRegs.put(7, new physicalFReg("ft7"));
        phyfRegs.put(28, new physicalFReg("ft8"));
        phyfRegs.put(29, new physicalFReg("ft9"));
        phyfRegs.put(30, new physicalFReg("ft10"));
        phyfRegs.put(31, new physicalFReg("ft11"));

        //浮点数s 寄存器
        phyfRegs.put(8, new physicalFReg("fs0"));
        phyfRegs.put(9, new physicalFReg("fs1"));
        phyfRegs.put(18, new physicalFReg("fs2"));
        phyfRegs.put(19, new physicalFReg("fs3"));
        phyfRegs.put(20, new physicalFReg("fs4"));
        phyfRegs.put(21, new physicalFReg("fs5"));
        phyfRegs.put(22, new physicalFReg("fs6"));
        phyfRegs.put(23, new physicalFReg("fs7"));
        phyfRegs.put(24, new physicalFReg("fs8"));
        phyfRegs.put(25, new physicalFReg("fs9"));
        phyfRegs.put(26, new physicalFReg("fs10"));
        phyfRegs.put(27, new physicalFReg("fs11"));

        //浮点数 a 寄存器
        phyfRegs.put(10, new physicalFReg("fa0"));
        fPhyA.put(0, phyfRegs.get(10));
        phyfRegs.put(11, new physicalFReg("fa1"));
        fPhyA.put(1, phyfRegs.get(11));
        phyfRegs.put(12, new physicalFReg("fa2"));
        fPhyA.put(2, phyfRegs.get(12));
        phyfRegs.put(13, new physicalFReg("fa3"));
        fPhyA.put(3, phyfRegs.get(13));
        phyfRegs.put(14, new physicalFReg("fa4"));
        fPhyA.put(4, phyfRegs.get(14));
        phyfRegs.put(15, new physicalFReg("fa5"));
        fPhyA.put(5, phyfRegs.get(15));
        phyfRegs.put(16, new physicalFReg("fa6"));
        fPhyA.put(6, phyfRegs.get(16));
        phyfRegs.put(17, new physicalFReg("fa7"));
        fPhyA.put(7, phyfRegs.get(17));
        SP.setNeedcolor(false);
        RA.setNeedcolor(false);
        //参数寄存器
        for (int key : phyA.keySet()) {
            phyA.get(key).setNeedcolor(false);
        }
    }
}
